package com.xjy.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class backLoginHandlerInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session= request.getSession();
        System.out.println(session.getAttribute("adminInfo"));
        //登录成功之后应该有用户session
        if(request.getRequestURI().contains("Login")){
            return true;
        }
        //说明我在提交登录
        if(request.getRequestURI().contains("login")){
            return true;
        }

        if (session.getAttribute("adminInfo") != null) {
            System.out.println("adminInfo=====》"+session.getAttribute("adminInfo"));
            return true;
        }

        request.getRequestDispatcher("toLoginPage").forward(request, response);
        return false;
    }
}
